package com.dk.controller;

import com.dk.data.PageBean;
import com.dk.data.Result;
import com.dk.domain.TCarDTO;
import com.dk.em.ConstantEnum;
import com.dk.feign.CarSeekFeign;
import com.dk.mapper.TCarMapper;
import com.dk.service.ITCarService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2021-11-01
 */
@RestController
@RequestMapping("/car")
public class TCarController {

    @Autowired
    private TCarMapper tCarMapper;

    @Autowired
    private ITCarService carService;

    @Autowired
    private CarSeekFeign carSeekFeign;

    @ApiOperation(value = "最新上架")
    @ApiImplicitParams({
            @ApiImplicitParam(name="startIndex",value = "开始下标",required = true,paramType = "query"),
            @ApiImplicitParam(name="pageSize",value = "每页条数",required = true,paramType = "query")
    })
    @GetMapping("findAllByTimeDesc")
    public Result findAllByTimeDesc(Integer startIndex,Integer pageSize){
        Result<List<TCarDTO>> result = carSeekFeign.getInfoByTime(startIndex, pageSize);
        List<TCarDTO> tCarDTOList = result.getResult();
        return Result.bulid(ConstantEnum.SUCCESS).setResult(tCarDTOList);
    }

    @ApiOperation(value = "按价格升序排序")
    @ApiImplicitParams({
            @ApiImplicitParam(name="num",value = "从第几条开始",required = true,paramType = "query"),
            @ApiImplicitParam(name="size",value = "查询多少条",required = true,paramType = "query")
    })
    @GetMapping("findAllByPriceAsc")
    public Result findAllByPriceAsc(Integer num,Integer size){
        PageBean pageBean = carService.findAllByPriceAsc(num,size);
        return Result.bulid(ConstantEnum.SUCCESS).setResult(pageBean);
    }

    @ApiOperation(value = "按价格降序排序")
    @ApiImplicitParams({
            @ApiImplicitParam(name="num",value = "从第几条开始",required = true,paramType = "query"),
            @ApiImplicitParam(name="size",value = "查询多少条",required = true,paramType = "query")
    })
    @GetMapping("findAllByPriceDesc")
    public Result findAllByPriceDesc(Integer num,Integer size){
        PageBean pageBean = carService.findAllByPriceDesc(num,size);
        return Result.bulid(ConstantEnum.SUCCESS).setResult(pageBean);
    }

    @ApiOperation(value = "按车龄降序排序")
    @ApiImplicitParams({
            @ApiImplicitParam(name="num",value = "从第几条开始",required = true,paramType = "query"),
            @ApiImplicitParam(name="size",value = "查询多少条",required = true,paramType = "query")
    })
    @GetMapping("findAllByAgeDesc")
    public Result findAllByAgeDesc(Integer num,Integer size){
        PageBean pageBean = carService.findAllByAgeDesc(num,size);
        return Result.bulid(ConstantEnum.SUCCESS).setResult(pageBean);
    }

    @ApiOperation(value = "按里程升序排序")
    @ApiImplicitParams({
            @ApiImplicitParam(name="num",value = "从第几条开始",required = true,paramType = "query"),
            @ApiImplicitParam(name="size",value = "查询多少条",required = true,paramType = "query")
    })
    @GetMapping("findAllByMileageAsc")
    public Result findAllByMileageAsc(Integer num,Integer size){
        PageBean pageBean = carService.findAllByMileageAsc(num,size);
        return Result.bulid(ConstantEnum.SUCCESS).setResult(pageBean);
    }
}
